home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6346 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  134 lines

  1. Path: ni1.ni.net!usenet
  2. From: Jeff Nikodym <jeffnik@ni.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: [Q] MSVC2.0 Windows Messaging...
  5. Date: Thu, 08 Feb 1996 20:34:47 -0800
  6. Organization: Network Intensive
  7. Message-ID: <311ACEE7.7679@ni.net>
  8. NNTP-Posting-Host: jeffnik.ni.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
  13.  
  14. I'm new to MSVC2.0, and I'm trying my hand at Winsock for 
  15. the first time (probably a BAD combination!). I cant get the 
  16. WSAAsyncGetHostByAddr() function to call back my message handler. 
  17. The WSA function runs, and I see the command go over the modem 
  18. (I have an external), and the RCV light blinks as well (I assume 
  19. this is an ACK *OR* possibly the information being returned). 
  20. Problem is, once done, the WSA function should send a message back 
  21. to the window, which should cause the window to start the OnmyMsg() 
  22. message handler routine. The handle returned by the WSA
  23. function after the call is valid (1 the first call, 2 the second 
  24. call, etc) and the WSAGetLastError function returns no error, 
  25. but the hostent struct (myHostEnt) contains no new information, and 
  26. OnmyMsg() handler never runs. Here is the code that relates to this 
  27. discussion. If some C++ expert could give it a quick scan, and tell
  28. me what I might be doing wrong, Id greatly appreciate it. Thanks!
  29.  
  30.  
  31. ***** Heres the MainFrame.h file *****
  32. class CMainFrame : public CFrameWnd
  33. {
  34. protected: // create from serialization only
  35.     CMainFrame();
  36.     DECLARE_DYNCREATE(CMainFrame)
  37.  
  38. // Attributes
  39. public:
  40.  
  41. // Operations
  42. public:
  43. // Overrides
  44.     // ClassWizard generated virtual function overrides
  45.     //{{AFX_VIRTUAL(CMainFrame)    
  46.     //}}AFX_VIRTUAL
  47.     
  48.  
  49. // Implementation
  50. public:
  51.     virtual ~CMainFrame();
  52. #ifdef _DEBUG
  53.     virtual void AssertValid() const;
  54.     virtual void Dump(CDumpContext& dc) const;
  55. #endif
  56.  
  57. protected:  // control bar embedded members
  58.     CStatusBar  m_wndStatusBar;
  59.     CToolBar    m_wndToolBar;
  60.  
  61. // Generated message map functions
  62. protected:
  63. //{{AFX_MSG(CMainFrame)
  64.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  65.     afx_msg void OnHelpInfo();    
  66.     afx_msg void OnmyMsg();
  67.     afx_msg void OnAppExit();
  68.     afx_msg void OnHelpHost();
  69.     //}}AFX_MSG
  70.     DECLARE_MESSAGE_MAP()
  71.     
  72. };
  73.  
  74.  
  75. ***** In the MainFrame.CPP file: *****
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CMainFrame
  78.  
  79. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  80.  
  81. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  82.     //{{AFX_MSG_MAP(CMainFrame)
  83.     ON_WM_CREATE()
  84.     ON_COMMAND(IDD_HELP_INFO, OnHelpInfo)
  85.     ON_COMMAND(WM_myMsg, OnmyMsg)
  86.     ON_COMMAND(ID_APP_EXIT, OnAppExit)
  87.     ON_COMMAND(IDD_HELP_HOST, OnHelpHost)
  88.     //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90.  
  91. void CMainFrame::OnHelpInfo() 
  92. {
  93.     // TODO: Add your command handler code here
  94.     char myBuffer[100];
  95.     int  myBufferLen=100,LastError;
  96.     unsigned long addr;
  97.     
  98.     HANDLE PASCAL FAR my_Handle;    
  99.  
  100.     addr=inet_addr("199.107.69.182");        
  101.     my_Handle=WSAAsyncGetHostByAddr(m_hWnd, WM_myMsg,(const char *) &addr, 4, PF_INET, (char 
  102. FAR *)&myHostEnt,sizeof(myHostEnt));
  103.     LastError=WSAGetLastError();
  104.     wsprintf(myBuffer, "Handle: %d Last Error: %d 
  105. WinsockInitialized=%d",my_Handle,LastError,WinsockInitialized);
  106.     if (LastError!=0)MessageBox(myBuffer);
  107.  
  108. }
  109.  
  110. void CMainFrame::OnmyMsg() 
  111. {
  112.      // TODO: Add your command handler code here
  113.     MessageBox("Message Received","Yeah!",MB_OK);        
  114. }
  115.  
  116. void CMainFrame::OnAppExit() 
  117. {
  118.  if (WinsockInitialized==TRUE)    
  119.     {
  120.      WSACleanup();
  121.     }  
  122. }
  123.  
  124.  
  125.  
  126. ***** After running I get: *****
  127.  
  128. Loaded symbols for 'C:\WINDOWS\SYSTEM\MFC30D.DLL'.
  129. MFC30D.DLL Initializing!
  130. First-Chance Exception in server.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
  131. Thread 0xFFFA217B terminated, exit code -1 (0xFFFFFFFF).
  132. MFC30D.DLL Terminating!
  133. Process 0xFFF904D7 terminated, exit code 0 (0x0).
  134.